﻿using System;
using Mutzl.Samples.VideoApp.Common;
using Mutzl.Samples.VideoApp.Player_C_YouTube.Model;
using Mutzl.Samples.VideoApp.YouTube.Model;
using Mutzl.Samples.VideoApp.YouTube.ViewModel;
using Windows.UI.Xaml.Controls;

namespace Mutzl.Samples.VideoApp.YouTube.View
{
    public sealed partial class MainView : LayoutAwarePage
    {

        //Todo: C08. Hintergrund (statisches Bild) und/oder Video in Endlosschleife im XAML Zeile 65-66 anpassen

        public MainView()
        {
            InitializeComponent();
            ItemGridView.LayoutUpdated += ItemGridView_LayoutUpdated;
        }


        private MainViewModel ViewModel { get { return DataContext as MainViewModel; } }

        void ItemGridView_LayoutUpdated(object sender, object e)
        {
            if (ItemGridView.RenderSize.Height > 30)
                TweetList.Height = ItemGridView.RenderSize.Height - 30;
        }

        void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Navigate to the appropriate destination page, configuring the new page
            // by passing required information as a navigation parameter
            var video = ((Video)e.ClickedItem);
            //Frame.Navigate(typeof(DetailView), video);  // exception bei Suspend, weil komplexe Typen nicht serialisierbar sind -> id.
            Frame.Navigate(typeof(DetailView), video.Id);

        }

        private async void TweetList_OnItemClick(object sender, ItemClickEventArgs e)
        {
            var tweet = (Tweet)e.ClickedItem;
            await Windows.System.Launcher.LaunchUriAsync(tweet.Link);
        }
    }
}